package com.evaluationsystem.system.serivce.impl;

import com.evaluationsystem.system.entity.PullMessage;
import com.evaluationsystem.system.entity.WechatMpProperties;
import com.evaluationsystem.system.serivce.WechatPushTaskMessage;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WechatPushTaskMessageImpl implements WechatPushTaskMessage {

    @Autowired
    WechatMpProperties wechatMpProperties;

    @Autowired
    WxMpService weMpService;


    @Override
    public void pushMeetingCheckinMessage(List<Map<String, Object>> staffInfos)  {
        PullMessage msg = new PullMessage();

        msg.setFirst("first");
        msg.setKeyword1("keyword1");
        msg.setKeyword2("keyword2");
        msg.setKeyword3("keyword3");
        msg.setKeyword4("keyword4");
        msg.setRemark("remark");
        msg.setDetailUrl("link");

        WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
        templateMessage.setToUser("oIAj0vrmljsAVJ3Zs7IGXvnVYZ5U");
        templateMessage.setTemplateId(wechatMpProperties.getInvoiceTemplateId());
        templateMessage.addData(new WxMpTemplateData("first", msg.getFirst()));
        templateMessage.addData(new WxMpTemplateData("keyword1", msg.getKeyword1()));
        templateMessage.addData(new WxMpTemplateData("keyword2", msg.getKeyword2()));
        templateMessage.addData(new WxMpTemplateData("keyword3", msg.getKeyword3()));
        templateMessage.addData(new WxMpTemplateData("remark", msg.getRemark()));
        templateMessage.setUrl(msg.getDetailUrl());
        try {
            weMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
    }
}
